﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace TeamBuy.AccessWebUI
{
    public partial class Unverified : System.Web.UI.Page
    {
        DataTable dtUser;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != "" && Request.QueryString["ID"] != null)
            {
                TeamBuy.AccessService.TeamBuyUserService userInfo = new AccessService.TeamBuyUserService();
                dtUser = userInfo.GetUser(Convert.ToInt32(Common.PublicFunction.DESDecrypt(Request.QueryString["ID"].ToString())));
                ltlUserEmail.Text = dtUser.Rows[0]["UserEmail"].ToString();
            }
            else
            {
                Response.Redirect("~/Login.aspx");
            }
        }

        protected void btnResendActiveLink_Click(object sender, EventArgs e)
        {
            if (dtUser != null)
            {
                string activeLink = AccessService.TeamBuySystemInfo.SiteDomain + "/ActiveUser.aspx?ID=" + Common.PublicFunction.DESEncrypt(dtUser.Rows[0]["UserID"].ToString()) + "&Date=" + Common.PublicFunction.DESEncrypt(dtUser.Rows[0]["DateCreated"].ToString()) + "&Mail=" + Common.PublicFunction.DESEncrypt(dtUser.Rows[0]["UserEmail"].ToString());

                if (Common.PublicFunction.SendMailToUser(AccessService.TeamBuySystemInfo.ActiveEmailAddress, dtUser.Rows[0]["UserEmail"].ToString(), "感谢注册" + AccessService.TeamBuySystemInfo.SiteName + "，请验证Email", "Hi " + dtUser.Rows[0]["UserName"].ToString() + ",<br /><br />感谢您注册" + AccessService.TeamBuySystemInfo.SiteName + "，请点击下面的链接验证您的Email：<br /><br /><a href='http://" + activeLink + "' target='_blank'>点击激活帐户</a><br /><br /><br />" + AccessService.TeamBuySystemInfo.SiteName, AccessService.TeamBuySystemInfo.ActiveEmailSMTP, Convert.ToInt32(AccessService.TeamBuySystemInfo.ActiveEmailPort), AccessService.TeamBuySystemInfo.ActiveEmailPassword) == true)
                {
                    btnResendActiveLink.Visible = false;
                    ltlNotSendLink.Visible = false;
                    ltlSendLink.Visible = true;
                }
                else
                {
                    ltlNotSendLink.Visible = true;
                }
                //Response.Redirect("~/Reged.aspx?RegedUserID=" + Common.PublicFunction.DESEncrypt(dtUser.Rows[0]["UserID"].ToString()));
            }

        }
    }
}